import java.util.Random;
import java.util.Scanner;
public class pig {
	public static void main(String[] args) {
		System.out.println("If a player rolls a 1, that player loses all points for that round and the dice go to the other player.\n  If a player rolls two 1s in one roll (snake  eyes), that player loses all points earned so far in the game and loses control of the dice.\n  The player may voluntarily turn over the dice after any roll.\n  So the player must decide to either roll again (be a pig) and risk losing points, or give up the dice.");
		//create random generator
		PairofDice MJsDice = new PairofDice();
		Scanner scan = new Scanner(System.in);
		int playerScore= 0 , computerScore = 0, playerScoreRound = 0, computerScoreRound = 0;
		int playerRoll = 0, playerRoll2 = 0, computerRoll = 0, computerRoll2 = 0;
		String rollAgainAnswer;
		boolean rollAgain = true;
		boolean playerRolled1 , playerSnakeEyes , computerRolled;
		MJsDice.rollDice();
		while( (playerScore < 100 ) && ( computerScore < 100 ) ) {
			playerScoreRound = 0;
			rollAgain = true;
			while( (snakeEyes(playerRoll , playerRoll2 ) == 0 ) && rollAgain) {
				MJsDice.rollDice();
				playerRoll = MJsDice.getResult1();
				playerRoll2 = MJsDice.getResult2();
				//playerRoll = MJsDice.getTotal();
				playerScoreRound += playerRoll;
				System.out.println("You have rolled a " + playerRoll + ".");
				System.out.println("Your score for this round is:" + playerScoreRound );
				System.out.println("Roll again? (Y/n)");
				rollAgainAnswer = scan.next();
				rollAgain = (rollAgainAnswer.equals("Y") || rollAgainAnswer.equals("y"));
				}
			if(snakeEyes(playerRoll , playerRoll2 ) == 2) {
				playerScore = 0;
			}
			else if(snakeEyes(playerRoll , playerRoll2 ) == 1) {
				playerScoreRound = 0;
			}
			else {
				playerScore += playerScoreRound;
			}
			computerScoreRound = 0;
			rollAgain = true;
			while( (snakeEyes(computerRoll , computerRoll2 ) == 0 ) && (computerScoreRound < 20)) {
				MJsDice.rollDice();
				computerRoll = MJsDice.getResult1();
				computerRoll2 = MJsDice.getResult2();
				//computerRoll = MJsDice.getTotal();
				computerScoreRound += MJsDice.getTotal();
				System.out.println("The computer has rolled a " + computerRoll + ".");
				System.out.println("The computer's score for this round is:" + computerScoreRound );
				System.out.println("Roll again? (Y/n)");
				
				System.out.println("The computer has rolled over 20, and is giving up its turn.");
			}
			if(snakeEyes(computerRoll , computerRoll2 ) == 2) {
				computerScore = 0;
			}
			else if(snakeEyes(computerRoll , computerRoll2 ) == 1) {
				computerScoreRound = 0;
			}
			else {
				computerScore += computerScoreRound;
			}
			System.out.println("Your Score is:" + playerScore);
			System.out.println("The computers score is:" + computerScore);
			playerRoll = 0;
			playerRoll2 = 0;
			computerRoll = 0;
			computerRoll2 = 0;
			rollAgain = true;
			playerScoreRound = 0;
			
			}
		}
		//generate number from 1-6

		//0 = no 1s, 1 = one 1, 2 = two 1s
		public static int snakeEyes(int roll1 , int roll2) {
			if( ( roll1 == 1 ) && ( roll2 == 1 ) ) {
				return 2;
			}
			else if( ( roll1 == 1 ) ^ ( roll2 == 1) ) {
				return 1;
			}
			else {
				return 0;
			}
		}
}
